<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { useRoute } from 'vue-router';

import { ElButton, ElResult } from 'element-plus';

import { authApi } from '#/api';
import { router } from '#/router';

defineOptions({ name: 'Register' });
const route = useRoute();
const isCodeValid = ref(true);
const activateResult = ref('激活成功！');

onMounted(async () => {
  if (route.params.code) {
    try {
      await authApi.activeUserApi(route.params.code as string);
    } catch {
      isCodeValid.value = false;
      activateResult.value = '该用户已激活！';
    }
  }
});
</script>

<template>
  <ElResult
    icon="success"
    :title="activateResult"
    sub-title="点击下方按钮去登录"
  >
    <template #extra>
      <ElButton size="large" type="primary" @click="router.push('/auth/login')">
        去登录
      </ElButton>
    </template>
  </ElResult>
</template>
